// pages/user/detailDriver/index.js
import request from '../../../baseRequest.js'
import urls from '../../../requestUrl.js'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        
        },
    /**获取救援司机信息 */
    getDriverInfo() {
        let param = {
            'openid': this.data.openid
        }
        request.postRequest(urls.driver.getDriverInfo, param, (res) => {
            let info = res.resData
            let driverLience = []
            info.driverLience ? driverLience.push(info.driverLience) : ''
            info.driverLience = driverLience
            let drivingLience = []
            info.drivingLience ? drivingLience.push(info.drivingLience) : ''
            info.drivingLience = drivingLience
            info.companyRegion = info.companyRegion ? info.companyRegion.split(',') : null
            info.gender = info.gender==='male'? '男':'女'
            this.setData({
                info: info
            })
        }, () => {})
    },
    /**前往修改页面 */
    handleToEditInfo() {
        wx.navigateTo({
            url: '/pages/user/registerDriver/index?type=2',
        })
    },
    /**解绑司机认证 */
    handleToResetInfo() {
        wx.showModal({
            title: '温馨提示',
            content: '是否确认解绑当前认证的身份？解绑后需重新进行会员认证审核',
            confirmText: '立即解绑',
            success: res => {
                if (res.confirm) {
                    let param = { 'openid': this.data.openid }
                    request.postRequest(urls.driver.cancelDriver, param, (res) => {
                        //重置司机未认证状态
                        getApp().updateGlobalUserDriverStatus('-1')
                        wx.showModal({
                            content: '解绑成功,请返回重新认证会员',
                            showCancel: false,
                            success: res => {
                                wx.navigateBack()
                            }
                        })
                    }, () => {})
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.data.openid = getApp().getUserOpenid()
        if(!this.data.openid){
            this.setData({
                openid:wx.getStorageSync('openid'),
            })
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        this.getDriverInfo()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    }
})
